package cn.sdjzu.exercise;

import cn.sdjzu.exercise.db.DBHelper;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class HistoryTrainingActivity extends BasedActivity {

	private TextView mModeAddmuscle;
	private TextView mModeReducefat;
	private TextView mModeBodybuilding;
	private TextView mModeAddforce;
	private ExerciseApp app;
	private DBHelper dbHelper;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ExerciseApp.getInstance().addActivity(this);
		setContentView(R.layout.history_training);
		app = (ExerciseApp) HistoryTrainingActivity.this.getApplication();
		dbHelper = new DBHelper(this);
		DBNoDataToast=Toast.makeText(this, "提取数据出错", Toast.LENGTH_LONG);
		mModeAddmuscle = (TextView) findViewById(R.id.history_exercise_mode_addmuscle);
		mModeReducefat = (TextView) findViewById(R.id.history_exercise_mode_reducefat);
		mModeBodybuilding = (TextView) findViewById(R.id.history_exercise_mode_bodybuilding);
		mModeAddforce = (TextView) findViewById(R.id.history_exercise_mode_addforce);

		// 增加肌肉模式的锻炼次数
		int addmuscletimes=0;
		try {
			addmuscletimes = Integer.parseInt(dbHelper.getDataFromDB(
					DBHelper.TBL_EXERCISE,
					DBHelper.TBL_EXERCISE_MODE_ADDMUSCLE_TIMES,
					app.currentCardNo));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 减肥模式的锻炼次数
		int reducefattiems=0;
		try {
			reducefattiems = Integer.parseInt(dbHelper.getDataFromDB(
					DBHelper.TBL_EXERCISE,
					DBHelper.TBL_EXERCISE_MODE_REDUCEFAT_TIMES,
					app.currentCardNo));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 健美模式的锻炼次数
		int bodybuildingtimes=0;
		try {
			bodybuildingtimes = Integer.parseInt(dbHelper.getDataFromDB(
					DBHelper.TBL_EXERCISE,
					DBHelper.TBL_EXERCISE_MODE_BODYBUILDING_TIMES,
					app.currentCardNo));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 增加力量模式的锻炼次数
		int addforcetimes=0;
		try {
			addforcetimes = Integer.parseInt(dbHelper.getDataFromDB(
					DBHelper.TBL_EXERCISE,
					DBHelper.TBL_EXERCISE_MODE_ADDFORCE_TIMES,
					app.currentCardNo));
		} catch (Exception e) {
			e.printStackTrace();
		}

		mModeAddmuscle.setText(getResources().getQuantityString(
				R.plurals.history_exercise_mode_times, addmuscletimes,
				addmuscletimes));
		mModeReducefat.setText(getResources().getQuantityString(
				R.plurals.history_exercise_mode_times, reducefattiems,
				reducefattiems));
		mModeBodybuilding.setText(getResources().getQuantityString(
				R.plurals.history_exercise_mode_times, bodybuildingtimes,
				bodybuildingtimes));
		mModeAddforce.setText(getResources().getQuantityString(
				R.plurals.history_exercise_mode_times, addforcetimes,
				addforcetimes));
	}

	@Override
	public void onBackPressed() {
		Intent intent = new Intent(this, ControlPanelActivity.class);
		startActivity(intent);
		this.finish();
	}
}
